package com.cn.springcloudwechat.controller.pay.weixin;

import com.cn.springcloudwechat.common.ajax.AjaxRes;
import com.cn.springcloudwechat.common.utils.Const;
import com.cn.springcloudwechat.common.utils.ThreadLocalUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 李贵
 * @Date: Created in 16:04 2018/5/7
 * @Content:
 */
@RestController
@RequestMapping("/web/")
public class WeiPayController {



//
//    @Autowired
//    private PaymentService paymentService;
    /**
     * 微信公众号支付
     * @param body
     * @return
     */
    @RequestMapping("pay")
    public AjaxRes pay(AjaxRes ajaxRes, String body, Integer totalFee,String orderId){
        Map<Object,Object> data= new HashMap<>();
        try {
            String openid = ThreadLocalUtil.getUser().getRegisterChannelId();
            if(openid==null){
                throw new IllegalArgumentException("openId为空");
            }
            WeiXinPay weiXinPay = new WeiXinPay();
            data = weiXinPay.pay(body,totalFee,openid,orderId);
            ajaxRes.setSucceed(data, Const.DATA_SUCCEED);
            System.out.println("微信支付:"+data);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }


}
